/*
 * Created on 27/mar/07
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package it.unibo.deis.lia.mmhc.test;

import it.unibo.deis.lia.mmhc.mpe.*;

import java.util.logging.*;

public class MPETestMobilware08 extends Thread {

	private boolean debug = false;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new MPETestMobilware08().start();
	}

	public void run() {
		Logger logger = Logger.getLogger("MobilWare08");
		try {
			Handler handler = new FileHandler("./log/MobilWare08_1db_3ms.txt");
			// Handler handler=new FileHandler("c:/condivisi/log.txt");
			// System.out.println("1 handler.getLevel() "+handler.getLevel());
			handler
					.setFormatter(new it.unibo.deis.lia.mmhc.test.logger.CarloFormatter());
			// System.out.println("0 logger.getHandlers() "+logger.getHandlers().length);
			logger.addHandler(handler);

			// Tolgo il loggi su stderr
			Handler parentHandler = logger.getParent().getHandlers()[0];
			logger.getParent().removeHandler(parentHandler);

			// System.out.println("!!! parent "+logger.getParent().getHandlers()[0]);
			// System.out.println("1 logger.getHandlers() "+logger.getParent().getHandlers().length);
			// System.out.println("1 logger.getLevel() "+logger.getLevel());
			logger.setLevel(Level.ALL);
			// System.out.println("2 logger.getLevel() "+logger.getLevel());
		} catch (Exception e) {
			e.printStackTrace();
		}

		try {
			System.out.println("MobilityEstimatorTest start");
			MobilityEstimator mobilityEstimator = MobilityEstimator
					.getInstance(/*
								 * MobilityEstimator.SIMULATED,MobilityEstimator.
								 * UNUSED
								 */);
			// mobilityEstimator.startMobilityEstimator();
			int minutes = 10;
			int seconds = minutes * 60;
			for (int i = 0; i < seconds; i++) {
				// while(true){
				if (debug) {
					System.out.println("MobilityEstimatorTest MobilityDegree "
							+ mobilityEstimator.getMobilityDegree());
					System.out.println("MobilityEstimatorTest MobilityState "
							+ mobilityEstimator.getMobilityState());
					System.out.println("MobilityEstimatorTest Joint "
							+ mobilityEstimator.getJoint());
					System.out.println();
				}
				logger.info("State " + mobilityEstimator.getMobilityState());
				System.out
						.println("MobilityEstimatorTest " + i + "/" + seconds);
				Thread.sleep(1000);
			}
		} catch (Exception e) {
			e.printStackTrace(System.out);
		}
		System.out.println("MobilityEstimatorTest finish");
	}
}
